import type { Column } from "@/components/CrudPage/type";
import { IconSelect } from "@/components/ReIcon";
import { ref } from "vue";

import { delete{{.ClassName}}, type {{.ClassName}} } from "@/views/domain/{{.DomainLower}}/api/{{.ClassNameLower}}";
import { messager } from "@/utils/message";

export function use{{.ClassName}}Provider() {

  // 列配置
  const columns: Column[] = [
    {{- range .Fields}}
    {
        label: "{{.Comment}}",
        prop: "{{.JsonName}}",
        slot: "{{.JsonName}}",
        search: {{- if .InSearch}}true{{- else -}}false{{- end}},
        create: {{- if .InCreate}}true{{- else -}}false{{- end}},
        edit: {{- if .InEdit}}true{{- else -}}false{{- end}},
        colProps: {span: 12},
        // cellRenderer: ({ row }) => (<div />) // render in table
        // renderField: (value, onChange) => (<div/>) // render in form
    },
    {{- end}}
    {
      label: "操作",
      prop: "operation",
      slot: "operation"
    }
  ];

  // 删除row
  const deleteRow = (row: {{.ClassName}}) => {
    delete{{.ClassName}}(row).then(({ ok, msg }) => {
      messager.alert(ok, msg);
    });
  };

  return {
    columns,
    deleteRow
  };
}
